home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-taskin.ads < prev    next >
Text File  |  1994-05-19  |  12KB  |  395 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                        S Y S T E M . T A S K I N G                       --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.5 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1991,1992,1993, FSU, All Rights Reserved         --
  12. --                                                                          --
  13. --  GNARL is free software; you can redistribute it and/or modify it  under --
  14. --  terms  of  the  GNU  Library General Public License as published by the --
  15. --  Free Software Foundation; either version 2,  or (at  your  option)  any --
  16. --  later  version.   GNARL is distributed in the hope that it will be use- --
  17. --  ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
  18. --  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. --  eral Library Public License for more details.  You should have received --
  20. --  a  copy of the GNU Library General Public License along with GNARL; see --
  21. --  file COPYING. If not, write to the Free Software Foundation,  675  Mass --
  22. --  Ave, Cambridge, MA 02139, USA.                                          --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. --  This package provides the necessary type definitions for compiler
  27. --  interface. A number of definitions has to be private. However,
  28. --  current version does not provide private definitions (compiler error)
  29.  
  30. with System.Task_Primitives;
  31. --  Used for,  Task_Primitives.Lock
  32.  
  33. package System.Tasking is
  34.  
  35.    --  This part has to be deleted when private part become stable.
  36.    --  Commented out definitions has to be enabled for these types.
  37.  
  38.    Max_ATC_Nesting : constant Natural := 20;
  39.    type Call_Modes is (Simple_Call, Conditional_Call, Asynchronous_Call);
  40.  
  41.    type Protection;
  42.    type Protection_Access is access Protection;
  43.  
  44.    Null_Entry : constant := 0;
  45.  
  46.    Max_Entry : constant := System.Max_Int;
  47.  
  48.    Interrupt_Entry : constant := -2;
  49.  
  50.    Cancelled_Entry : constant := -1;
  51.  
  52.    type Entry_Index is range Interrupt_Entry .. Max_Entry;
  53.  
  54.    Null_Task_Entry : constant := Null_Entry;
  55.  
  56.    Max_Task_Entry : constant := Max_Entry;
  57.  
  58.    type Task_Entry_Index is new Entry_Index
  59.      range Null_Task_Entry .. Entry_Index (Max_Task_Entry);
  60.    --  Unnecessary conversion is to get round GNAT version 1.79 bug ???
  61.  
  62.    Null_Protected_Entry : constant := Null_Entry;
  63.  
  64.    Max_Protected_Entry : constant := Max_Entry;
  65.  
  66.    type Protected_Entry_Index is new Entry_Index
  67.      range Null_Protected_Entry .. Entry_Index (Max_Protected_Entry);
  68.    --  Unnecessary conversion is to get round GNAT version 1.79 bug ???
  69.  
  70.    --  Rendezvous related definitions
  71.  
  72.    Max_Select : constant Integer := Integer'Last;
  73.    --  RTS-defined
  74.  
  75.    subtype Select_Index is Integer range 0 .. Max_Select;
  76.    --  This is a subtype so that operations on it will be visible to
  77.    --  the code generated by GNAT.
  78.  
  79.    type Accept_Alternative is record --  should be packed
  80.       Null_Body : Boolean;
  81.       S : Task_Entry_Index;
  82.    end record;
  83.  
  84.    subtype Positive_Select_Index is
  85.      Select_Index range 1 .. Select_Index'Last;
  86.  
  87.    type Accept_List is
  88.      array (Positive_Select_Index range <>) of Accept_Alternative;
  89.  
  90.    type Accept_List_Access is access constant Accept_List;
  91.  
  92.    --  These definitions have to go into private part later ???
  93.  
  94.    type Dummy is new Integer;
  95.  
  96.    type Task_ID is access Dummy;
  97.  
  98.    Null_Task : constant Task_ID := null;
  99.  
  100.    --  This should be a constant, but this package is not elaborated.
  101.    --  the following constant declartion doesn't seem to have problem.
  102.    --  if not being used, can be got rid of later. ???
  103.  
  104.    type Exception_ID is new Integer;
  105.  
  106.    Null_Exception      : constant Exception_ID := 0;
  107.    Constraint_Error_ID : constant Exception_ID := 1;
  108.    Numeric_Error_ID    : constant Exception_ID := 2;
  109.    Program_Error_ID    : constant Exception_ID := 3;
  110.    Storage_Error_ID    : constant Exception_ID := 4;
  111.    Tasking_Error_ID    : constant Exception_ID := 5;
  112.  
  113.    type tmp is record
  114.       d : integer;
  115.    end record;
  116.  
  117.    type Pre_Call_State is access tmp;
  118.  
  119.    --  Abortion related declarations
  120.  
  121.    subtype ATC_Level_Base is Integer range 0 .. Max_ATC_Nesting;
  122.  
  123.    ATC_Level_Infinity : constant ATC_Level_Base := ATC_Level_Base'Last;
  124.  
  125.    subtype ATC_Level is ATC_Level_Base range
  126.      ATC_Level_Base'First .. ATC_Level_Base'Last - 1;
  127.  
  128.    subtype ATC_Level_Index is ATC_Level
  129.      range ATC_Level'First + 1 .. ATC_Level'Last;
  130.  
  131.    type Task_List is array (Positive range <>) of Task_ID;
  132.  
  133.    --  Rendezvous related types
  134.  
  135.    Priority_Not_Boosted : constant Integer := System.Priority'First - 1;
  136.  
  137.    subtype Rendezvous_Priority is Integer
  138.      range Priority_Not_Boosted .. System.Priority'Last;
  139.  
  140.    type Select_Modes is (
  141.      Simple_Mode,
  142.      Else_Mode,
  143.      Terminate_Mode);
  144.  
  145.    --  Task Entry related definitions
  146.  
  147.    type Entry_Call_Record;
  148.  
  149.    type Entry_Call_Link is access Entry_Call_Record;
  150.  
  151.    type Entry_Queue is record
  152.       Head : Entry_Call_Link;
  153.       Tail : Entry_Call_Link;
  154.    end record;
  155.  
  156.    type Entry_Call_Record is record
  157.  
  158.       Next : Entry_Call_Link;
  159.  
  160.       Call_Claimed : Boolean;
  161.       --  This flag is True if the call has been queued
  162.       --  and subsequently claimed
  163.       --  for service or cancellation.
  164.       --  Protection : Test_And_Set/gloabal update or some similar mechanism
  165.       --  (e.g. global mutex).
  166.       --  Caution : on machines were we use Test_And_Set, we may not want this
  167.       --  field packed.  For example, the SPARC atomic ldsub instruction
  168.       --  effects a whole byte.
  169.  
  170.       Self  : Task_ID;
  171.       Level : ATC_Level;
  172.       --  One of Self and Level are redundent in this implementation, since
  173.       --  each Entry_Call_Record is at Self.Entry_Calls (Level).  Since we must
  174.       --  have access to the entry call record to be reading this, we could
  175.       --  get Self from Level, or Level from Self.  However, this requires
  176.       --  non-portable address arithmetic.
  177.  
  178.       Mode : Call_Modes;
  179.       Abortable : Boolean;
  180.  
  181.       Done : Boolean;
  182.       --  Protection : Self.L.
  183.  
  184.       E : Entry_Index;
  185.  
  186.       Prio : System.Any_Priority;
  187.  
  188.       --  The above fields are those that there may be some hope of packing.
  189.       --  They are gathered together to allow for compilers that lay records
  190.       --  out contigously, to allow for such packing.
  191.  
  192.       Uninterpreted_Data : System.Address;
  193.  
  194.       Exception_To_Raise : Exception_ID;
  195.       --  The exception to raise once this call has been completed without
  196.       --  being aborted.
  197.  
  198.       --  Server : Server_Record;
  199.  
  200.       Called_Task : Task_ID;
  201.       --  For task entry calls only.
  202.  
  203.       Acceptor_Prev_Call : Entry_Call_Link;
  204.       --  For task entry calls only.
  205.  
  206.       Acceptor_Prev_Priority : Rendezvous_Priority;
  207.       --  For task entry calls only.
  208.       --  The priority of the most recent prior call being serviced.
  209.       --  For protected entry calls, this function should be performed by
  210.       --  GNULLI ceiling locking.
  211.  
  212.       Called_PO : Protection_Access;
  213.       --  For protected entry calls only.
  214.  
  215.    end record;
  216.  
  217.    --  Protected_Objects replated definitions
  218.  
  219.    type Protected_Entry_Queue_Array is
  220.         array (Protected_Entry_Index range <>) of
  221.         Entry_Queue;
  222.  
  223.    type Protection (Num_Entries : Protected_Entry_Index) is tagged record
  224.         L : Task_Primitives.Lock;
  225.         Pending_Call : Entry_Call_Link;
  226.         Call_In_Progress : Entry_Call_Link;
  227.         Entry_Queues : Protected_Entry_Queue_Array (1 .. Num_Entries);
  228.    end record;
  229.  
  230.    type Master_ID is new